Reorganise test code
authorFelix Krull <f_krull@gmx.de>
Tue, 21 May 2019 17:28:49 +0000 (19:28 +0200)
committerColin Walters <walters@verbum.org>
Fri, 6 May 2022 16:53:53 +0000 (12:53 -0400)
This way I don't need to differentiate between tests for generated code
and tests for hand-written code.

rust-bindings/rust/src/collection_ref.rs [new file with mode: 0644]
rust-bindings/rust/src/collection_ref/mod.rs [deleted file]
rust-bindings/rust/src/collection_ref/tests.rs [deleted file]
rust-bindings/rust/src/lib.rs
rust-bindings/rust/src/repo.rs [new file with mode: 0644]
rust-bindings/rust/src/repo/mod.rs [deleted file]
rust-bindings/rust/src/repo/tests.rs [deleted file]
rust-bindings/rust/src/tests/collection_ref.rs [new file with mode: 0644]
rust-bindings/rust/src/tests/mod.rs [new file with mode: 0644]
rust-bindings/rust/src/tests/repo.rs [new file with mode: 0644]

diff --git a/rust-bindings/rust/src/collection_ref.rs b/rust-bindings/rust/src/collection_ref.rs
new file mode 100644 (file)
index 0000000..c99542e
--- /dev/null
@@ -0,0 +1,73 @@
+// Based on a file generated by gir. Changes are marked below.
+#[cfg(any(feature = "v2018_6", feature = "dox"))]
+use glib::translate::*;
+use glib_sys;
+use gobject_sys;
+use ostree_sys;
+use std::hash;
+
+glib_wrapper! {
+    #[derive(Debug, PartialOrd, Ord)]
+    pub struct CollectionRef(Boxed<ostree_sys::OstreeCollectionRef>);
+
+    match fn {
+        copy => |ptr| gobject_sys::g_boxed_copy(ostree_sys::ostree_collection_ref_get_type(), ptr as *mut _) as *mut ostree_sys::OstreeCollectionRef,
+        free => |ptr| gobject_sys::g_boxed_free(ostree_sys::ostree_collection_ref_get_type(), ptr as *mut _),
+        get_type => || ostree_sys::ostree_collection_ref_get_type(),
+    }
+}
+
+impl CollectionRef {
+    #[cfg(any(feature = "v2018_6", feature = "dox"))]
+    pub fn new(collection_id: Option<&str>, ref_name: &str) -> Option<CollectionRef> {
+        unsafe {
+            from_glib_full(ostree_sys::ostree_collection_ref_new(
+                collection_id.to_glib_none().0,
+                ref_name.to_glib_none().0,
+            ))
+        }
+    }
+
+    #[cfg(any(feature = "v2018_6", feature = "dox"))]
+    fn equal(&self, ref2: &CollectionRef) -> bool {
+        unsafe {
+            // CHANGE: both instances of *mut to *const
+            from_glib(ostree_sys::ostree_collection_ref_equal(
+                ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(self).0
+                    as glib_sys::gconstpointer,
+                ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(ref2).0
+                    as glib_sys::gconstpointer,
+            ))
+        }
+    }
+
+    #[cfg(any(feature = "v2018_6", feature = "dox"))]
+    fn hash(&self) -> u32 {
+        unsafe {
+            // CHANGE: *mut to *const
+            ostree_sys::ostree_collection_ref_hash(
+                ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(self).0
+                    as glib_sys::gconstpointer,
+            )
+        }
+    }
+}
+
+impl PartialEq for CollectionRef {
+    #[inline]
+    fn eq(&self, other: &Self) -> bool {
+        self.equal(other)
+    }
+}
+
+impl Eq for CollectionRef {}
+
+impl hash::Hash for CollectionRef {
+    #[inline]
+    fn hash<H>(&self, state: &mut H)
+    where
+        H: hash::Hasher,
+    {
+        hash::Hash::hash(&self.hash(), state)
+    }
+}
diff --git a/rust-bindings/rust/src/collection_ref/mod.rs b/rust-bindings/rust/src/collection_ref/mod.rs
deleted file mode 100644 (file)
index 35ea396..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-// Based on a file generated by gir. Changes are marked below.
-#[cfg(any(feature = "v2018_6", feature = "dox"))]
-use glib::translate::*;
-use glib_sys;
-use gobject_sys;
-use ostree_sys;
-use std::hash;
-
-glib_wrapper! {
-    #[derive(Debug, PartialOrd, Ord)]
-    pub struct CollectionRef(Boxed<ostree_sys::OstreeCollectionRef>);
-
-    match fn {
-        copy => |ptr| gobject_sys::g_boxed_copy(ostree_sys::ostree_collection_ref_get_type(), ptr as *mut _) as *mut ostree_sys::OstreeCollectionRef,
-        free => |ptr| gobject_sys::g_boxed_free(ostree_sys::ostree_collection_ref_get_type(), ptr as *mut _),
-        get_type => || ostree_sys::ostree_collection_ref_get_type(),
-    }
-}
-
-impl CollectionRef {
-    #[cfg(any(feature = "v2018_6", feature = "dox"))]
-    pub fn new(collection_id: Option<&str>, ref_name: &str) -> Option<CollectionRef> {
-        unsafe {
-            from_glib_full(ostree_sys::ostree_collection_ref_new(
-                collection_id.to_glib_none().0,
-                ref_name.to_glib_none().0,
-            ))
-        }
-    }
-
-    #[cfg(any(feature = "v2018_6", feature = "dox"))]
-    fn equal(&self, ref2: &CollectionRef) -> bool {
-        unsafe {
-            // CHANGE: both instances of *mut to *const
-            from_glib(ostree_sys::ostree_collection_ref_equal(
-                ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(self).0
-                    as glib_sys::gconstpointer,
-                ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(ref2).0
-                    as glib_sys::gconstpointer,
-            ))
-        }
-    }
-
-    #[cfg(any(feature = "v2018_6", feature = "dox"))]
-    fn hash(&self) -> u32 {
-        unsafe {
-            // CHANGE: *mut to *const
-            ostree_sys::ostree_collection_ref_hash(
-                ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(self).0
-                    as glib_sys::gconstpointer,
-            )
-        }
-    }
-}
-
-impl PartialEq for CollectionRef {
-    #[inline]
-    fn eq(&self, other: &Self) -> bool {
-        self.equal(other)
-    }
-}
-
-impl Eq for CollectionRef {}
-
-impl hash::Hash for CollectionRef {
-    #[inline]
-    fn hash<H>(&self, state: &mut H)
-    where
-        H: hash::Hasher,
-    {
-        hash::Hash::hash(&self.hash(), state)
-    }
-}
-
-#[cfg(test)]
-mod tests;
diff --git a/rust-bindings/rust/src/collection_ref/tests.rs b/rust-bindings/rust/src/collection_ref/tests.rs
deleted file mode 100644 (file)
index 5dc72de..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-use super::*;
-use std::collections::hash_map::DefaultHasher;
-use std::hash::{Hash, Hasher};
-
-fn hash(v: &impl Hash) -> u64 {
-    let mut s = DefaultHasher::new();
-    v.hash(&mut s);
-    s.finish()
-}
-
-#[test]
-fn same_value_should_be_equal() {
-    let r = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
-    assert_eq!(r, r);
-}
-
-#[test]
-fn equal_values_should_be_equal() {
-    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
-    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
-    assert_eq!(a, b);
-}
-
-#[test]
-fn equal_values_without_collection_id_should_be_equal() {
-    let a = CollectionRef::new(None, "ref-name").unwrap();
-    let b = CollectionRef::new(None, "ref-name").unwrap();
-    assert_eq!(a, b);
-}
-
-#[test]
-fn different_values_should_not_be_equal() {
-    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref1").unwrap();
-    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref2").unwrap();
-    assert_ne!(a, b);
-}
-
-#[test]
-fn new_with_invalid_collection_id_should_return_none() {
-    let r = CollectionRef::new(Some(".abc"), "ref");
-    assert_eq!(r, None);
-}
-
-#[test]
-fn hash_for_equal_values_should_be_equal() {
-    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
-    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
-    assert_eq!(hash(&a), hash(&b));
-}
-
-#[test]
-fn hash_for_values_with_different_collection_id_should_be_different() {
-    let a = CollectionRef::new(Some("io.gitlab.fkrull1"), "ref").unwrap();
-    let b = CollectionRef::new(Some("io.gitlab.fkrull2"), "ref").unwrap();
-    assert_ne!(hash(&a), hash(&b));
-}
-
-#[test]
-fn hash_for_values_with_different_ref_id_should_be_different() {
-    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref-1").unwrap();
-    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref-2").unwrap();
-    assert_ne!(hash(&a), hash(&b));
-}
-
-#[test]
-fn hash_should_be_different_if_collection_id_is_absent() {
-    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
-    let b = CollectionRef::new(None, "ref").unwrap();
-    assert_ne!(hash(&a), hash(&b));
-}
-
-#[test]
-fn clone_should_be_equal_to_original_value() {
-    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
-    let b = a.clone();
-    assert_eq!(a, b);
-}
index 6344ed1507261acfb31ad68f82fcede2ed1f61b5..5ac6af24d649252ae3c5515fc2bbf5b189c38d23 100644 (file)
@@ -13,22 +13,25 @@ extern crate lazy_static;
 
 use glib::Error;
 
-// re-exports
+// code generated by gir
 mod auto;
 pub use crate::auto::functions::*;
 pub use crate::auto::*;
 
-mod repo;
-
+// handwritten code
 #[cfg(any(feature = "v2018_6", feature = "dox"))]
 mod collection_ref;
+mod repo;
 #[cfg(any(feature = "v2018_6", feature = "dox"))]
-pub use crate::collection_ref::CollectionRef;
-
+pub use crate::collection_ref::*;
 mod object_name;
-pub use crate::object_name::ObjectName;
+pub use crate::object_name::*;
+
+// tests
+#[cfg(test)]
+mod tests;
 
-// public modules
+// prelude
 pub mod prelude {
     pub use crate::auto::traits::*;
     pub use crate::repo::RepoExtManual;
diff --git a/rust-bindings/rust/src/repo.rs b/rust-bindings/rust/src/repo.rs
new file mode 100644 (file)
index 0000000..3b493a8
--- /dev/null
@@ -0,0 +1,143 @@
+use crate::Repo;
+#[cfg(any(feature = "v2016_4", feature = "dox"))]
+use crate::RepoListRefsExtFlags;
+use gio;
+use glib;
+use glib::translate::*;
+use glib::Error;
+use glib::IsA;
+use glib_sys;
+use ostree_sys;
+use std::collections::{HashMap, HashSet};
+use std::path::Path;
+use std::ptr;
+use ObjectName;
+
+unsafe extern "C" fn read_variant_table(
+    _key: glib_sys::gpointer,
+    value: glib_sys::gpointer,
+    hash_set: glib_sys::gpointer,
+) {
+    let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant);
+    let set: &mut HashSet<ObjectName> = &mut *(hash_set as *mut HashSet<ObjectName>);
+    set.insert(ObjectName::new_from_variant(value));
+}
+
+unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable) -> HashSet<ObjectName> {
+    let mut set = HashSet::new();
+    glib_sys::g_hash_table_foreach(
+        ptr,
+        Some(read_variant_table),
+        &mut set as *mut HashSet<ObjectName> as *mut _,
+    );
+    glib_sys::g_hash_table_unref(ptr);
+    set
+}
+
+pub trait RepoExtManual {
+    fn new_for_path<P: AsRef<Path>>(path: P) -> Repo;
+
+    fn traverse_commit<P: IsA<gio::Cancellable>>(
+        &self,
+        commit_checksum: &str,
+        maxdepth: i32,
+        cancellable: Option<&P>,
+    ) -> Result<HashSet<ObjectName>, Error>;
+
+    // TODO: return GString?
+    fn list_refs<P: IsA<gio::Cancellable>>(
+        &self,
+        refspec_prefix: Option<&str>,
+        cancellable: Option<&P>,
+    ) -> Result<HashMap<String, String>, Error>;
+
+    #[cfg(any(feature = "v2016_4", feature = "dox"))]
+    fn list_refs_ext<P: IsA<gio::Cancellable>>(
+        &self,
+        refspec_prefix: Option<&str>,
+        flags: RepoListRefsExtFlags,
+        cancellable: Option<&P>,
+    ) -> Result<HashMap<String, String>, Error>;
+}
+
+impl<O: IsA<Repo>> RepoExtManual for O {
+    fn new_for_path<P: AsRef<Path>>(path: P) -> Repo {
+        Repo::new(&gio::File::new_for_path(path.as_ref()))
+    }
+
+    fn traverse_commit<P: IsA<gio::Cancellable>>(
+        &self,
+        commit_checksum: &str,
+        maxdepth: i32,
+        cancellable: Option<&P>,
+    ) -> Result<HashSet<ObjectName>, Error> {
+        unsafe {
+            let mut error = ptr::null_mut();
+            let mut hashtable = ptr::null_mut();
+            let _ = ostree_sys::ostree_repo_traverse_commit(
+                self.as_ref().to_glib_none().0,
+                commit_checksum.to_glib_none().0,
+                maxdepth,
+                &mut hashtable,
+                cancellable.map(|p| p.as_ref()).to_glib_none().0,
+                &mut error,
+            );
+            if error.is_null() {
+                Ok(from_glib_container_variant_set(hashtable))
+            } else {
+                Err(from_glib_full(error))
+            }
+        }
+    }
+
+    fn list_refs<P: IsA<gio::Cancellable>>(
+        &self,
+        refspec_prefix: Option<&str>,
+        cancellable: Option<&P>,
+    ) -> Result<HashMap<String, String>, Error> {
+        unsafe {
+            let mut error = ptr::null_mut();
+            let mut hashtable = ptr::null_mut();
+            let _ = ostree_sys::ostree_repo_list_refs(
+                self.as_ref().to_glib_none().0,
+                refspec_prefix.to_glib_none().0,
+                &mut hashtable,
+                cancellable.map(|p| p.as_ref()).to_glib_none().0,
+                &mut error,
+            );
+
+            if error.is_null() {
+                Ok(FromGlibPtrContainer::from_glib_container(hashtable))
+            } else {
+                Err(from_glib_full(error))
+            }
+        }
+    }
+
+    #[cfg(any(feature = "v2016_4", feature = "dox"))]
+    fn list_refs_ext<P: IsA<gio::Cancellable>>(
+        &self,
+        refspec_prefix: Option<&str>,
+        flags: RepoListRefsExtFlags,
+        cancellable: Option<&P>,
+    ) -> Result<HashMap<String, String>, Error> {
+        unsafe {
+            let mut error = ptr::null_mut();
+            let mut hashtable = ptr::null_mut();
+            let _ = ostree_sys::ostree_repo_list_refs_ext(
+                self.as_ref().to_glib_none().0,
+                refspec_prefix.to_glib_none().0,
+                &mut hashtable,
+                flags.to_glib(),
+                cancellable.map(|p| p.as_ref()).to_glib_none().0,
+                &mut error,
+            );
+
+            if error.is_null() {
+                Ok(FromGlibPtrContainer::from_glib_container(hashtable))
+            } else {
+                Err(from_glib_full(error))
+            }
+        }
+    }
+}
diff --git a/rust-bindings/rust/src/repo/mod.rs b/rust-bindings/rust/src/repo/mod.rs
deleted file mode 100644 (file)
index 220372e..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-use crate::Repo;
-#[cfg(any(feature = "v2016_4", feature = "dox"))]
-use crate::RepoListRefsExtFlags;
-use gio;
-use glib;
-use glib::translate::*;
-use glib::Error;
-use glib::IsA;
-use glib_sys;
-use ostree_sys;
-use std::collections::{HashMap, HashSet};
-use std::path::Path;
-use std::ptr;
-use ObjectName;
-
-unsafe extern "C" fn read_variant_table(
-    _key: glib_sys::gpointer,
-    value: glib_sys::gpointer,
-    hash_set: glib_sys::gpointer,
-) {
-    let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant);
-    let set: &mut HashSet<ObjectName> = &mut *(hash_set as *mut HashSet<ObjectName>);
-    set.insert(ObjectName::new_from_variant(value));
-}
-
-unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable) -> HashSet<ObjectName> {
-    let mut set = HashSet::new();
-    glib_sys::g_hash_table_foreach(
-        ptr,
-        Some(read_variant_table),
-        &mut set as *mut HashSet<ObjectName> as *mut _,
-    );
-    glib_sys::g_hash_table_unref(ptr);
-    set
-}
-
-pub trait RepoExtManual {
-    fn new_for_path<P: AsRef<Path>>(path: P) -> Repo;
-
-    fn traverse_commit<P: IsA<gio::Cancellable>>(
-        &self,
-        commit_checksum: &str,
-        maxdepth: i32,
-        cancellable: Option<&P>,
-    ) -> Result<HashSet<ObjectName>, Error>;
-
-    // TODO: return GString?
-    fn list_refs<P: IsA<gio::Cancellable>>(
-        &self,
-        refspec_prefix: Option<&str>,
-        cancellable: Option<&P>,
-    ) -> Result<HashMap<String, String>, Error>;
-
-    #[cfg(any(feature = "v2016_4", feature = "dox"))]
-    fn list_refs_ext<P: IsA<gio::Cancellable>>(
-        &self,
-        refspec_prefix: Option<&str>,
-        flags: RepoListRefsExtFlags,
-        cancellable: Option<&P>,
-    ) -> Result<HashMap<String, String>, Error>;
-}
-
-impl<O: IsA<Repo>> RepoExtManual for O {
-    fn new_for_path<P: AsRef<Path>>(path: P) -> Repo {
-        Repo::new(&gio::File::new_for_path(path.as_ref()))
-    }
-
-    fn traverse_commit<P: IsA<gio::Cancellable>>(
-        &self,
-        commit_checksum: &str,
-        maxdepth: i32,
-        cancellable: Option<&P>,
-    ) -> Result<HashSet<ObjectName>, Error> {
-        unsafe {
-            let mut error = ptr::null_mut();
-            let mut hashtable = ptr::null_mut();
-            let _ = ostree_sys::ostree_repo_traverse_commit(
-                self.as_ref().to_glib_none().0,
-                commit_checksum.to_glib_none().0,
-                maxdepth,
-                &mut hashtable,
-                cancellable.map(|p| p.as_ref()).to_glib_none().0,
-                &mut error,
-            );
-            if error.is_null() {
-                Ok(from_glib_container_variant_set(hashtable))
-            } else {
-                Err(from_glib_full(error))
-            }
-        }
-    }
-
-    fn list_refs<P: IsA<gio::Cancellable>>(
-        &self,
-        refspec_prefix: Option<&str>,
-        cancellable: Option<&P>,
-    ) -> Result<HashMap<String, String>, Error> {
-        unsafe {
-            let mut error = ptr::null_mut();
-            let mut hashtable = ptr::null_mut();
-            let _ = ostree_sys::ostree_repo_list_refs(
-                self.as_ref().to_glib_none().0,
-                refspec_prefix.to_glib_none().0,
-                &mut hashtable,
-                cancellable.map(|p| p.as_ref()).to_glib_none().0,
-                &mut error,
-            );
-
-            if error.is_null() {
-                Ok(FromGlibPtrContainer::from_glib_container(hashtable))
-            } else {
-                Err(from_glib_full(error))
-            }
-        }
-    }
-
-    #[cfg(any(feature = "v2016_4", feature = "dox"))]
-    fn list_refs_ext<P: IsA<gio::Cancellable>>(
-        &self,
-        refspec_prefix: Option<&str>,
-        flags: RepoListRefsExtFlags,
-        cancellable: Option<&P>,
-    ) -> Result<HashMap<String, String>, Error> {
-        unsafe {
-            let mut error = ptr::null_mut();
-            let mut hashtable = ptr::null_mut();
-            let _ = ostree_sys::ostree_repo_list_refs_ext(
-                self.as_ref().to_glib_none().0,
-                refspec_prefix.to_glib_none().0,
-                &mut hashtable,
-                flags.to_glib(),
-                cancellable.map(|p| p.as_ref()).to_glib_none().0,
-                &mut error,
-            );
-
-            if error.is_null() {
-                Ok(FromGlibPtrContainer::from_glib_container(hashtable))
-            } else {
-                Err(from_glib_full(error))
-            }
-        }
-    }
-}
-
-#[cfg(test)]
-mod tests;
diff --git a/rust-bindings/rust/src/repo/tests.rs b/rust-bindings/rust/src/repo/tests.rs
deleted file mode 100644 (file)
index de38812..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-use super::*;
-use crate::RepoMode;
-
-#[test]
-fn should_get_repo_mode_from_string() {
-    let mode = Repo::mode_from_string("archive").unwrap();
-    assert_eq!(RepoMode::Archive, mode);
-}
-
-#[test]
-fn should_return_error_for_invalid_repo_mode_string() {
-    let result = Repo::mode_from_string("invalid-repo-mode");
-    assert!(result.is_err());
-}
\ No newline at end of file
diff --git a/rust-bindings/rust/src/tests/collection_ref.rs b/rust-bindings/rust/src/tests/collection_ref.rs
new file mode 100644 (file)
index 0000000..9db3177
--- /dev/null
@@ -0,0 +1,77 @@
+use crate::CollectionRef;
+use std::collections::hash_map::DefaultHasher;
+use std::hash::{Hash, Hasher};
+
+fn hash(v: &impl Hash) -> u64 {
+    let mut s = DefaultHasher::new();
+    v.hash(&mut s);
+    s.finish()
+}
+
+#[test]
+fn same_value_should_be_equal() {
+    let r = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+    assert_eq!(r, r);
+}
+
+#[test]
+fn equal_values_should_be_equal() {
+    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+    assert_eq!(a, b);
+}
+
+#[test]
+fn equal_values_without_collection_id_should_be_equal() {
+    let a = CollectionRef::new(None, "ref-name").unwrap();
+    let b = CollectionRef::new(None, "ref-name").unwrap();
+    assert_eq!(a, b);
+}
+
+#[test]
+fn different_values_should_not_be_equal() {
+    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref1").unwrap();
+    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref2").unwrap();
+    assert_ne!(a, b);
+}
+
+#[test]
+fn new_with_invalid_collection_id_should_return_none() {
+    let r = CollectionRef::new(Some(".abc"), "ref");
+    assert_eq!(r, None);
+}
+
+#[test]
+fn hash_for_equal_values_should_be_equal() {
+    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+    assert_eq!(hash(&a), hash(&b));
+}
+
+#[test]
+fn hash_for_values_with_different_collection_id_should_be_different() {
+    let a = CollectionRef::new(Some("io.gitlab.fkrull1"), "ref").unwrap();
+    let b = CollectionRef::new(Some("io.gitlab.fkrull2"), "ref").unwrap();
+    assert_ne!(hash(&a), hash(&b));
+}
+
+#[test]
+fn hash_for_values_with_different_ref_id_should_be_different() {
+    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref-1").unwrap();
+    let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref-2").unwrap();
+    assert_ne!(hash(&a), hash(&b));
+}
+
+#[test]
+fn hash_should_be_different_if_collection_id_is_absent() {
+    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+    let b = CollectionRef::new(None, "ref").unwrap();
+    assert_ne!(hash(&a), hash(&b));
+}
+
+#[test]
+fn clone_should_be_equal_to_original_value() {
+    let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+    let b = a.clone();
+    assert_eq!(a, b);
+}
diff --git a/rust-bindings/rust/src/tests/mod.rs b/rust-bindings/rust/src/tests/mod.rs
new file mode 100644 (file)
index 0000000..6726a27
--- /dev/null
@@ -0,0 +1,2 @@
+mod collection_ref;
+mod repo;
diff --git a/rust-bindings/rust/src/tests/repo.rs b/rust-bindings/rust/src/tests/repo.rs
new file mode 100644 (file)
index 0000000..59a6792
--- /dev/null
@@ -0,0 +1,14 @@
+use crate::Repo;
+use crate::RepoMode;
+
+#[test]
+fn should_get_repo_mode_from_string() {
+    let mode = Repo::mode_from_string("archive").unwrap();
+    assert_eq!(RepoMode::Archive, mode);
+}
+
+#[test]
+fn should_return_error_for_invalid_repo_mode_string() {
+    let result = Repo::mode_from_string("invalid-repo-mode");
+    assert!(result.is_err());
+}